package org.example.orders_learn.config;


import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;

@Configuration
@WithStateMachine
@Slf4j
// 配置状态机事件
// 定义状态机事件，并指定触发事件时执行的操作
public class StateMachineEventConfig {


    @OnTransition(target = "STANDBY")
    public void init()
    {
        log.info("====@OnTransition====");
        log.info("待处理状态");
        log.info("===target = \"PAID\"===");
    }



    @OnTransition(source = "STANDBY", target = "UNPAID")//初始
    public void create()
    {
        log.info("====@OnTransition====");
        log.info("订单创建未支付");
        log.info("===target = \"UNPAID\"===");
    }

    @OnTransition(source = "UNPAID", target = "PAID")
    public void pay()
    {
        log.info("====@OnTransition====");
        log.info("订单支付完成，待收货");
        log.info("===target = \"PAID\"===");
    }

    @OnTransition(source = "PAID", target = "SHIPPED")
    public void ship()
    {
        log.info("====@OnTransition====");
        log.info("订单已发货");
        log.info("===target = \"SHIPPED\"===");
    }

    @OnTransition(source = "SHIPPED", target = "RECEIVED")
    public void receive()
    {
        log.info("====@OnTransition====");
        log.info("订单已收货");
        log.info("===target = \"RECEIVED\"===");
    }

    @OnTransition(source = "RECEIVED", target = "STANDBY")
    public void finish()
    {
        log.info("====@OnTransition====");
        log.info("订单已完成");
        log.info("===target = \"STANDBY\"===");
    }

}

